package com.hejing.反射的应用;

import org.junit.Test;

import java.lang.reflect.Field;

/**
 * ClassName: FieldTest
 * Package: com.hejing.反射的应用
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-06-04 19:04
 * @Version: 1.0
 */
public class FieldTest {
    @Test
    public void test01(){

        Class clazz = Person.class;
        // getFields(): 获取到运行时类本身及其所有的父类中声明为public 权限的属性
        Field[] fields = clazz.getFields();
        for (Field f: fields) {
            System.out.println(f);
        }
        System.out.println("**************************************************************");
        // getDeclaredFields(): 获取当前运行时类中声明的所有属性
        Field[] declaredFields = clazz.getDeclaredFields();
        for(Field f: declaredFields) {
            System.out.println(f);
        }
    }
}
























